<template>
	<view class="content">
		<view class="components-posts">
			<!-- 搜索框 -->
			<view class="components-search">
				<u-search placeholder="点击搜索相关资讯" :clearabled="true" @focus="toArticleListPage"></u-search>
			</view>
			<!-- 首页轮播图 -->
			<view class="components-carousel">
				<u-swiper :list="carouselList" img-mode="scaleToFill" :effect3d=true height="350"></u-swiper>
			</view>
			<!-- 首页推荐项 -->
			<view class="components-article">
				<homeArticle :articleIndexData="articleIndexData"></homeArticle>
			</view>
		</view>
		<tabbar-footer></tabbar-footer>
	</view>
</template>

<script>
	import {
		getAppIndexList
	} from '@/api/home/home.js'
	import homeArticle from './home-article.vue'
	import tabbarFooter from '../tabbar/tabbar-footer.vue'
	export default {
		data () {
			return {
				carouselList: [
					'../../static/pic-1.jpg',
					'../../static/pic-2.jpg',
					'../../static/pic-3.jpg'
				],
				articleIndexData: []
			}
		},
		onLoad () {
			this.getAppIndexList()
		},
		components: {
			homeArticle,
			tabbarFooter
		},
		methods: {
			// 跳转搜索页面
			toArticleListPage() {
				uni.navigateTo({
					url: '/pages/article/article-list'
				});
			},
			// 获取首页推荐文章
			getAppIndexList() {
				getAppIndexList().then(res => {
					this.articleIndexData = res.data
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.content {
		display: flex;
		flex-direction: column;
	}
	
	.components-search {
		margin: 10rpx 10rpx 10rpx 10rpx;
	}
	
	.components-carousel {
		justify-content: center;
		align-items: center;
		margin: 20rpx 0rpx 20rpx 0rpx;
	}
	
	.components-article {
		
	}
</style>